package sugarbind_input

class Source {

    String source_Name
	String supplier
	
    static constraints = {
		source_Name(blank:false)		
		supplier(nullable:true)

		organism(nullable:true)
		ligands(nullable:true)
		
		source_Name(unique:['source_Type','supplier','organism'])
	}
	
	static hasOne = [source_Type:Source_Type, organism:Organism]

	static hasMany = [ligands:Ligand]
	static belongsTo = [Ligand]
	
	
	static mapping = {
//		id column: 'source_id'
		id generator: 'sequence', params: [sequence: 'source_id_seq']

		ligands joinTable: [name: "ligand_source", key: 'source_id' ]
	}
	
	public String toString(){
		def source =""
		source += source_Type.source_Type_Name + " : " 
		source += source_Name + " (" + id +")"
		if(organism != null)
		{
			source += " / organism : "+ organism.toString()
		}
		if(supplier != null)
		{
			source += " / supplier : " + supplier 
		}
		source   //+ " " +area_Type + " " + host.host_Name
	}
	
	public static listSources()
	{
		Source.list().sort{ it.toString(); }
	}
}
